package com.ict.web.controller.yzq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ict.common.utils.StringUtils;
import com.ict.web.dto.AnnualDeclarationAddDto;
import com.ict.web.dto.AnnualDeclarationEditDto;
import com.ict.web.vo.AnnualDeclarationVo;
import com.ict.web.vo.AnnualProjectPlanListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ict.common.annotation.Log;
import com.ict.common.core.controller.BaseController;
import com.ict.common.core.domain.AjaxResult;
import com.ict.common.enums.BusinessType;
import com.ict.web.domain.AnnualDeclaration;
import com.ict.web.service.IAnnualDeclarationService;
import com.ict.common.utils.poi.ExcelUtil;
import com.ict.common.core.page.TableDataInfo;

/**
 * 年度申报--刘杰Controller
 *
 * @author liujie
 * @date 2022-02-25
 */
@Api(tags = "年度申报")
@RestController
@RequestMapping("/annualDeclaration")
public class AnnualDeclarationController extends BaseController
{
    @Autowired
    private IAnnualDeclarationService annualDeclarationService;



    /**
     * 查询 年度项目计划 名称
     */
    @ApiOperation("查询年度项目计划名称")
    @GetMapping("/listAnnualName")
    public List<AnnualProjectPlanListVo> selectAnnualName(AnnualProjectPlanListVo vo){
        if (StringUtils.isEmpty(vo.getIsState())) {
            vo.setIsState("44");
        }
        return annualDeclarationService.selectAnnualName(vo);
    }

    /**
     * 查询年度申报--刘杰列表
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:list')")
    @ApiOperation("查询年度申报")
    @GetMapping("/list")
    public TableDataInfo list(AnnualDeclaration annualDeclaration)
    {
        startPage();
        List<AnnualDeclaration> list = annualDeclarationService.selectAnnualDeclarationList(annualDeclaration);
        return getDataTable(list);
    }

    /**
     * 导出年度申报--刘杰列表
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:export')")
    @ApiOperation("导出年度申报")
    @Log(title = "年度申报--刘杰", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AnnualDeclaration annualDeclaration)
    {
        List<AnnualDeclaration> list = annualDeclarationService.selectAnnualDeclarationList(annualDeclaration);
        ExcelUtil<AnnualDeclaration> util = new ExcelUtil<AnnualDeclaration>(AnnualDeclaration.class);
        util.exportExcel(response, list, "年度申报");
    }

    /**
     * 获取年度申报--刘杰详细信息
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:query')")
    @ApiOperation("获取年度申报")
    @GetMapping(value = "/{annualId}")
    public AnnualDeclarationVo getInfo(@PathVariable("annualId") Long annualId)
    {
        return annualDeclarationService.selectAnnualDeclarationByAnnualId(annualId);
    }

    /**
     * 新增年度申报--刘杰
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:add')")
    @ApiOperation("新增年度申报")
    @Log(title = "年度申报--刘杰", businessType = BusinessType.INSERT)
    @PostMapping
    public Long add(@RequestBody AnnualDeclarationAddDto dto)
    {
        return annualDeclarationService.insertAnnualDeclaration(dto);
    }

    /**
     * 修改年度申报--刘杰
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:edit')")
    @ApiOperation("修改年度申报")
    @Log(title = "年度申报--刘杰", businessType = BusinessType.UPDATE)
    @PutMapping("/edit/{annualId}")
    public AjaxResult edit(@RequestBody AnnualDeclarationEditDto dto,@PathVariable Long annualId)
    {
        return toAjax(annualDeclarationService.updateAnnualDeclaration(dto,annualId));
    }

    /**
     * 删除年度申报--刘杰
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:remove')")
    @ApiOperation("删除年度申报")
    @Log(title = "年度申报--刘杰", businessType = BusinessType.DELETE)
	@DeleteMapping("/{annualId}")
    public AjaxResult remove(@PathVariable Long annualId)
    {
        return toAjax(annualDeclarationService.deleteAnnualDeclarationByAnnualId(annualId));
    }
    /**
     * 获取建设单位和所属部门
     */
    @GetMapping("/getUnitAndDept/{orgCategory}")
    public AjaxResult getUnitAndDept(@PathVariable String orgCategory) {
        return AjaxResult.success(annualDeclarationService.getUnitAndDept(orgCategory));
    }

}
